package com.yl.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageInfo;
import com.yl.common.core.domain.AjaxResult;
import com.yl.common.core.page.TableDataInfo;
import com.yl.common.utils.SecurityUtils;
import com.yl.common.utils.StringUtils;
import com.yl.domain.UserDO;
import com.yl.mapper.UserMapper;
import com.yl.service.UserService;
import com.yl.utils.CommonUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 用户表
 *
 * @author : y
 * @description :
 * @date : 2024/6/3 17:01
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;


    /**
     * 根据token获取当前用户信息
     *
     * @author : y
     * @date :  2024/6/4 9:20
     **/
    @Override
    public UserDO getByToken() {
        UserDO byId = userMapper.selectById(SecurityUtils.getUserId());
        if (byId != null) {
            return byId;
        }
        return null;
    }

    /**
     * 注册司机账号
     *
     * @param userDO
     * @author : y
     * @date :  2024/6/4 9:27
     */
    @Override
    public AjaxResult save(UserDO userDO) {

        return AjaxResult.success("操作成功");
    }

    /**
     * 查询司机列表
     *
     * @param userDO
     * @author : y
     * @date :  2024/6/4 9:43
     */
    @Override
    public TableDataInfo findPage(UserDO userDO) {
        TableDataInfo info = CommonUtils.getTableDataInfo();
        List<UserDO> page = userMapper.findPage(userDO);
        if (page != null && page.size() != 0) {
            info.setRows(page);
            info.setTotal(new PageInfo<>(page).getTotal());
        }
        return info;

    }
}
